package com.briup.bookstore.web.controller;

import com.briup.bookstore.response.Result;
import com.briup.bookstore.service.CollectService;
import com.briup.bookstore.vo.CollectVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author briup-adam
 * @Date 2023/7/25 下午2:29
 * @Description
 **/

@RestController
@Api(tags = "收藏模块")
@RequestMapping("/collect")
public class CollectController {
    @Autowired
    private CollectService collectService;

    @GetMapping("/")
    @ApiOperation("获取用户收藏信息")
    public Result getCollects(HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        List<CollectVO> list = collectService.findCollects(Integer.parseInt(userId));
        return  Result.success(list);
    }
    @PostMapping("/{id}")
    @ApiOperation("用户新增收藏")
    public Result  addCollect(@PathVariable("id") Integer bookId, HttpServletRequest request){
        String userId = (String) request.getAttribute("userId");
        collectService.addCollect(Integer.parseInt(userId),bookId);
        return  Result.success();
    }
    @DeleteMapping("/")
    @ApiOperation("删除用户收藏")
    public  Result deleteCollect(@RequestBody Integer... ids){
        collectService.deleteCollect(ids);
        return  Result.success();
    }

}
